﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace mapleHttpTestServer.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class FishController : ControllerBase
    {
        private readonly FishDataset database;

        public FishController()
        {
            database = new FishDataset();
        }


        // GET: api/<FishController>
        [HttpGet]
        public IEnumerable<Fish> Get()
        {
            return database.List();
        }


        // GET api/<FishController>/5
        [HttpGet("{id}")]
        public Fish Get(long id)
        {
            return database.Get(id);
        }

        // POST api/<FishController>
        [HttpPost]
        public void Post([FromBody] Fish fish)
        {
            Console.WriteLine($"Request.ContentType:{ Request.ContentType }");

            database.Post(fish);
        }

        [HttpPost, Route("post2")]
        public void Post2([FromForm] Fish fish)
        {
            Console.WriteLine($"Request.ContentType:{ Request.ContentType }");

            database.Post(fish);
        }

        // PUT api/<FishController>/5
        [HttpPut("{id}")]
        public void Put(long id, [FromBody] Fish fish)
        {
            database.Put(id,fish);
        }

        // DELETE api/<FishController>/5
        [HttpDelete("{id}")]
        public void Delete(long id)
        {
            database.Delete(id);
        }
    }
}
